package com.xuzz.xrpc.spring.context;

import com.xuzz.xrpc.common.utils.ClassUtils;
import org.springframework.beans.factory.FactoryBean;

/**
 * @description:
 * @author: xuzz
 * @create: 2020-02-21 17:40
 */
public class ReferenceBean implements FactoryBean {
    String interfaceName;

    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    @Override
    public Object getObject() throws Exception {
        //这里返回代理
        //代理工厂，在listener中已经添加
        return null;
    }

    @Override
    public Class<?> getObjectType() {
        return getInterfaceClass();
    }

    public Class<?> getInterfaceClass() {
        Class<?> interfaceClass = null;
        try {
            if (interfaceName != null && interfaceName.length() > 0) {
                interfaceClass = Class.forName(interfaceName, true, ClassUtils.getClassLoader());
            }
        } catch (ClassNotFoundException t) {
            throw new IllegalStateException(t.getMessage(), t);
        }

        return interfaceClass;
    }
}
